// MigDb.cpp : Defines the entry point for the console application.
//

#include <Common/include.h>
#include <Database/Database.h>
#include <Database/Tables/TableNames.h>

void to_0_2_0(CDatabase* pDb);

int _tmain(int argc, _TCHAR* argv[])
{
	std::tstring strVer = _T("0.1.1");
	CDatabase db(JOURNAL_DATABASE_NAME);
	db.Open();
	if(db.IsExistTable(VERSION_DB_TABLE_NAME)){
		std::tstring strRequest(_T("SELECT version FROM "));
		MyTable table = db.ExecRequest(strRequest + VERSION_DB_TABLE_NAME);
		strVer = table[0][0].m_strValueColumn;
	}else{
		std::tstring strRequest(_T("CREATE TABLE "));
		db.ExecRequest(strRequest + VERSION_DB_TABLE_NAME + _T("(version TEXT NOT NULL);"));
		strRequest = _T("INSERT INTO ");
		db.ExecRequest(strRequest + VERSION_DB_TABLE_NAME + _T(" VALUES('0.1.1');"));
	}
	if(strVer == _T("0.1.1")){
		printf("modify database to 0.2.0");
		to_0_2_0(&db);
		strVer = _T("0.2.0");
	}
	std::tstring strRequest(_T("UPDATE "));
	db.ExecRequest(strRequest + VERSION_DB_TABLE_NAME + _T(" SET version='") + strVer + _T("';"));
	return 0;
}

